<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");

$_LangPath = "accountlist";
include_once(__Member_Path."/logincheck_member_report.php");
include_once(__Language_Path."/selectlanguage_member.php");
$_data["LottoID"] = 1;
@include_once(__Common_Path."/todaygame/Gamble".$_data["LottoID"].".inc.php");

if(is_array($_arrGamble)){
	list($intGID, $arrGamble) = each($_arrGamble);
	if($arrGamble[GameDate] == date("Y-m-d") && $arrGamble[EndGameTime] < date("H:i:s")){
		$GLOBALS["errormessage"] = $_strAccountList["onCountResult"];//"結帳中，請稍後！！";
		ErrMsgOutputHTML("Error", "", 1);
	}
}

$fp = @file(__Membertemplate_Path."/account_list.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
$fp = str_replace("{Name}", $_SESSION["Member_Info"] -> Name, $fp);
$fp = str_replace("{ShowDate}", date("Y-m-d"), $fp);

//以下位置不可上下移動
while(list($k, $v) = each($_strAccountList)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

preg_match("/<!--@ BetContent While Start @\/\/-->(.+)<!--@ BetContent While End @\/\/-->/s", $fp, $BetContent);

$arrToday = split("-", date("Y-m-d"));
$strSDate = date("Y-m-d", mktime(0, 0, 0, $arrToday[1], $arrToday[2] - 7, $arrToday[0]));
$strEDate = date("Y-m-d", mktime(0, 0, 0, $arrToday[1], $arrToday[2] + 1, $arrToday[0]));

$time_start = getMicro_Time(); 
$strSQL = "select PayupDate, SUM(MemStake) as MemStake, SUM(SubIncome) as SubIncome from `bet_BetList` where (PayupDate between '".$strSDate."' and '".$strEDate."') and MemID = ".$_SESSION["Member_Info"] -> ID." and isPayOff = 0 group by PayupDate";
if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Error";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}
$arrRows = array();
if(PMA_mysql_num_rows($RS) > 0){
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrRows[$Rows -> PayupDate] = $Rows;
	}
}
$time_end = getMicro_Time(); 

$totalStake = 0;
$totalSubIncome = 0;
for($i = -1; $i < 8; $i++){
	$intTime = mktime(0, 0, 0, $arrToday[1], $arrToday[2] - $i, $arrToday[0]);
	$PayupDate = date("Y-m-d", $intTime);
	$BetWeek = $_arrWeek[date("w", $intTime)];

	$Rows = $arrRows[$PayupDate];
	if($Rows -> PayupDate != ""){
		$totalStake += $Rows -> MemStake;
		$totalSubIncome += $Rows -> SubIncome;
		$tmpCon = str_replace("{P_BetDate}", "bethistory_list.php?PayupDate=".$PayupDate, $BetContent[1]);
		$tmpCon = str_replace("{Show_BetDate}", $PayupDate, $tmpCon);
		$tmpCon = str_replace("{Show_BetWeek}", $BetWeek, $tmpCon);
		$tmpCon = str_replace("{MemStake}", $Rows -> MemStake, $tmpCon);
		$tmpCon = str_replace("{SubIncome}", sprintf("%.1f", $Rows -> SubIncome), $tmpCon);
	}else{
		$tmpCon = str_replace("{P_BetDate}", "#", $BetContent[1]);
		$tmpCon = str_replace("{Show_BetDate}", $PayupDate, $tmpCon);
		$tmpCon = str_replace("{Show_BetWeek}", $BetWeek, $tmpCon);
		$tmpCon = str_replace("{MemStake}", 0, $tmpCon);
		$tmpCon = str_replace("{SubIncome}", 0, $tmpCon);
	}
	$AllCon .= $tmpCon;
}

$fp = preg_replace("/<!--@ BetContent While Start @\/\/-->.+<!--@ BetContent While End @\/\/-->/s", $AllCon, $fp);
$fp = str_replace("{TotalStake}", $totalStake, $fp);
$fp = str_replace("{TotalSubIncome}", sprintf("%.1f", $totalSubIncome), $fp);

$fp .= "<a style='font-size: 10px; color: #DDDDDD'>".(string)($time_end - $time_start)."</a>";//<!--".$strSQL."//-->";
//輸出
WebOutputHTML($fp, 1);
?>